/*
 * Transaction.java
 *
 * Created on March 14, 2007, 3:46 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package edu.byu.isys413.samlam;

import java.util.LinkedList;
import java.util.List;

/**
 * Transaction
 * @author Sam
 */
public class Transaction extends BusinessObject{
   
    private Customer customer;
    private List<TransactionLine> txLinesList;
    private Payment payment;
    private String type;
    private String status;
    private Employee employee;
    private long date;
    private Store store;
    private final double TAX_RATE = .062;
    
    /** Creates a new instance of Transaction */
    public Transaction(String id) {
       super(id);
       txLinesList = new LinkedList();
    }


    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
        this.setDirty(true);
    }

    public List<TransactionLine> getTxLinesList() {
        return txLinesList;
    }

    public void setTxLinesList(List<TransactionLine> txLinesList) {
        this.txLinesList = txLinesList;
        this.setDirty(true);
    }
    
    public void addTransactionLine(TransactionLine txline){

            txLinesList.add(txline);
    }

    public Payment getPayment() {
        return payment;
    }

    public void setPayment(Payment payment) {
        this.payment = payment;
        this.setDirty(true);
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
        this.setDirty(true);
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
        this.setDirty(true);
    }

    public Employee getEmployee() {
        return employee;
    }

    public void setEmployee(Employee employee) {
        this.employee = employee;
        this.setDirty(true);
    }

    public double getTax() {
        double tax;
        tax = this.getSubtotal()*TAX_RATE;
        return tax;
    }

    public double getSubtotal() {
        double subtotal = 0;
        for (int i = 0 ; i < this.txLinesList.size(); i++){
            double linetotal=0;
            if(this.txLinesList.get(i).getRevenueSource() != null){
            linetotal += this.txLinesList.get(i).getRevenueSource().getPrice();
            linetotal *= this.txLinesList.get(i).getQuantity();
            }else if (this.txLinesList.get(i).getCoupon() != null){
            linetotal += this.txLinesList.get(i).getCoupon().getAmount();       
            }
            subtotal += linetotal;
        }
        return subtotal;
    }

    public double getTotal() {
        double total = this.getSubtotal()+this.getTax();
        return total;
    }


    public long getDate() {
        return date;
    }

    public void setDate(long date) {
        this.date = date;
        this.setDirty(true);
    }

    public Store getStore() {
        return store;
    }

    public void setStore(Store store) {
        this.store = store;
        this.setDirty(true);
    }
}
